﻿using System.Linq;
using System.Web.Mvc;
using BlogElements.Models;

namespace BlogElements.Controllers
{
    public class PostController : Controller
    {
        BlogElementsEntities blogDB = new BlogElementsEntities();

        public ActionResult Index()
        {
            var items = blogDB.PostTags.ToList();
            var posts = blogDB.Posts.ToList();
            var tags = blogDB.Tags.ToList();
            return View(posts);
        }

        //
        // GET: /Home/Browse?tag=ASP.NET

        public ActionResult Browse(string tag)
        {
            var posts = blogDB.Posts.ToList();
            var tags = blogDB.Tags.ToList();
            var tagModel = blogDB.Tags.Include("PostTags").Include("Posts").Single(g => g.Name == tag);

            return View(tagModel);
        }

        //
        // GET: /Home/Post/2

        public ActionResult Post(int id)
        {
            var post = blogDB.Posts.Find(id);

            return View(post);
        }

        //
        // GET: /Post/Tags

        [ChildActionOnly]
        public ActionResult Tags()
        {
            var tags = blogDB.Tags.ToList();

            return PartialView(tags);
        }

    }
}
